package com.life.ai.server.framework.osssts;

import com.aliyuncs.sts.model.v20150401.AssumeRoleRequest;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * OssStsProperties
 *
 * @author kylewka
 * @since 2023/7/25
 */
@Data
@Component
@ConfigurationProperties(prefix = "storage.oss-sts")
public class OssStsProperties {

    /**
     * 单应用设置名称
     */
    private String roleName = "life";

    private String regionId = "cn-hangzhou";

    private String accessKeyId;

    private String accessKeySecret;

    private String roleArn;

    private String policy;

    /**
     * STS有效期
     */
    private Long duration = 3600L;

    /**
     * 系统刷新有效期(必须小于STS有效期)
     */
    private Long cacheDuration = 3000L;

    @SneakyThrows
    public AssumeRoleRequest assumeRoleRequest(String roleSessionName) {
        AssumeRoleRequest request = new AssumeRoleRequest();
        request.setRoleArn(roleArn);
        request.setPolicy(policy);
        request.setDurationSeconds(duration);
        request.setRoleSessionName(roleSessionName);
        return request;
    }
}
